home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / gnulib2.c < prev    next >
C/C++ Source or Header  |  1993-09-22  |  31KB  |  1,669 lines

  1. /* WARNING: compile this in 32 bit int mode even for short library */
  2. #include <string.h>
  3. #include <memory.h>
  4. #ifndef _COMPILER_H
  5. #include <compiler.h>
  6. #endif
  7.  
  8. #ifdef __DEF_ALL__    /* this def'ed when making on the ST */
  9.  
  10. #define L_adddi3
  11. #define L_subdi3
  12. #define L_muldi3
  13. #define L_divdi3
  14. #define L_moddi3
  15. #define L_udivdi3
  16. #define L_umoddi3
  17. #define L_negdi2
  18. #define L_anddi3
  19. #define L_iordi3
  20. #define L_xordi3
  21. #define L_lshrdi3
  22. #define L_lshldi3
  23. #define L_ashldi3
  24. #define L_ashrdi3
  25. #define L_one_cmpldi2
  26. #define L_bdiv
  27. #define L_cmpdi2
  28. #define L_ucmpdi2
  29. #define L_fixunsdfdi
  30. #define L_fixdfdi
  31. #define L_floatdidf
  32.  
  33. /* gcc-2.0 stuff */
  34. #if 0    /* NOTE: these are now covered, and should not be generated here */
  35. #define L_lshrsi3
  36. #define L_lshlsi3
  37. #define L_ashrsi3
  38. #define L_ashlsi3
  39. #define L_eqdf2
  40. #define L_nedf2
  41. #define L_gtdf2
  42. #define L_gedf2
  43. #define L_ltdf2
  44. #define L_ledf2
  45. #define L_fixsfsi
  46. #define L_floatsisf
  47. #define L_eqsf2
  48. #define L_nesf2
  49. #define L_gtsf2
  50. #define L_gesf2
  51. #define L_ltsf2
  52. #define L_lesf2
  53. #endif
  54. #define L_fxussfsi
  55. #define L_gccbcmp
  56.  
  57. #endif /* __DEF_ALL__ */
  58.  
  59. /* More subroutines needed by GCC output code on some machines.  */
  60. /* Compile this one with gcc.  */
  61.  
  62. #if 0
  63. #include "config.h"    /* dont drag this in, just define relevant
  64.                stuff from xm/tm-atari.h & xm/tm-m68k.h here */
  65. #else
  66.  
  67. /* #defines that need visibility everywhere.  */
  68. #define FALSE 0
  69. #define TRUE 1
  70.  
  71. /* This describes the machine the compiler is hosted on.  */
  72. #define HOST_BITS_PER_CHAR 8
  73. #define HOST_BITS_PER_SHORT 16
  74. #define HOST_BITS_PER_INT 32
  75. #define HOST_BITS_PER_LONG 32
  76.  
  77. /* Define this if most significant bit is lowest numbered
  78.    in instructions that operate on numbered bit-fields.
  79.    This is true for 68020 insns such as bfins and bfexts.
  80.    We make it true always by avoiding using the single-bit insns
  81.    except in special cases with constant bit numbers.  */
  82. #define BITS_BIG_ENDIAN
  83.  
  84. /* Define this if most significant byte of a word is the lowest numbered.  */
  85. /* That is true on the 68000.  */
  86. #define BYTES_BIG_ENDIAN
  87.  
  88. /* Define this if most significant word of a multiword number is numbered.  */
  89. /* For 68000 we can decide arbitrarily
  90.    since there are no machine instructions for them.  */
  91. #define WORDS_BIG_ENDIAN
  92.  
  93. /* number of bits in an addressible storage unit */
  94. #define BITS_PER_UNIT 8
  95.  
  96. /* Width in bits of a "word", which is the contents of a machine register.
  97.    Note that this is not necessarily the width of data type `int';
  98.    if using 16-bit ints on a 68000, this would still be 32.
  99.    But on a machine with 16-bit registers, this would be 16.  */
  100. #define BITS_PER_WORD 32
  101.  
  102. /* Width of a word, in units (bytes).  */
  103. #define UNITS_PER_WORD 4
  104.  
  105. /* Width in bits of a pointer.
  106.    See also the macro `Pmode' defined below.  */
  107. #define POINTER_SIZE 32
  108.  
  109. /* Allocation boundary (in *bits*) for storing pointers in memory.  */
  110. #define POINTER_BOUNDARY 16
  111.  
  112. /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
  113. #define PARM_BOUNDARY (TARGET_SHORT ? 16 : 32)
  114.  
  115. /* Boundary (in *bits*) on which stack pointer should be aligned.  */
  116. #define STACK_BOUNDARY 16
  117.  
  118. /* Allocation boundary (in *bits*) for the code of a function.  */
  119. #define FUNCTION_BOUNDARY 16
  120.  
  121. /* Alignment of field after `int : 0' in a structure.  */
  122. #define EMPTY_FIELD_BOUNDARY 16
  123.  
  124. /* No data type wants to be aligned rounder than this.  */
  125. #define BIGGEST_ALIGNMENT 16
  126.  
  127. /* Define this if move instructions will actually fail to work
  128.    when given unaligned data.  */
  129. #define STRICT_ALIGNMENT
  130.  
  131. /* Define number of bits in most basic integer type.
  132.    (If undefined, default is BITS_PER_WORD).  */
  133. #ifdef __MSHORT__
  134. #define INT_TYPE_SIZE 16
  135. #else
  136. #define INT_TYPE_SIZE 32
  137. #endif
  138.  
  139. #endif
  140.  
  141. #ifndef minix
  142. #include <stddef.h>
  143. #else
  144.      typedef unsigned long size_t;
  145. #include "lib.h"
  146. #endif
  147.  
  148. #ifndef SItype
  149. #define SItype long int
  150. #endif
  151.  
  152. /* long long ints are pairs of long ints in the order determined by
  153.    WORDS_BIG_ENDIAN.  */
  154.  
  155. #ifdef WORDS_BIG_ENDIAN
  156.   struct longlong {long high, low;};
  157. #else
  158.   struct longlong {long low, high;};
  159. #endif
  160.  
  161. /* We need this union to unpack/pack longlongs, since we don't have
  162.    any arithmetic yet.  Incoming long long parameters are stored
  163.    into the `ll' field, and the unpacked result is read from the struct
  164.    longlong.  */
  165.  
  166. typedef union
  167. {
  168.   struct longlong s;
  169.   long long ll;
  170.   SItype i[2];
  171.   unsigned SItype ui[2];
  172. } long_long;
  173.  
  174. /* Internally, long long ints are strings of unsigned shorts in the
  175.    order determined by BYTES_BIG_ENDIAN.  */
  176.  
  177. #define B 0x10000
  178. #define low16 (B - 1)
  179.  
  180. #ifdef BYTES_BIG_ENDIAN
  181.  
  182. /* Note that HIGH and LOW do not describe the order
  183.    of words in a long long.  They describe the order of words
  184.    in vectors ordered according to the byte order.  */
  185.  
  186. #define HIGH 0
  187. #define LOW 1
  188.  
  189. #define big_end(n)    0 
  190. #define little_end(n)    ((n) - 1)
  191. #define next_msd(i)    ((i) - 1)
  192. #define next_lsd(i)    ((i) + 1)
  193. #define is_not_msd(i,n)    ((i) >= 0)
  194. #define is_not_lsd(i,n)    ((i) < (n))
  195.  
  196. #else
  197.  
  198. #define LOW 0
  199. #define HIGH 1
  200.  
  201. #define big_end(n)    ((n) - 1)
  202. #define little_end(n)    0 
  203. #define next_msd(i)    ((i) + 1)
  204. #define next_lsd(i)    ((i) - 1)
  205. #define is_not_msd(i,n)    ((i) < (n))
  206. #define is_not_lsd(i,n)    ((i) >= 0)
  207.  
  208. #endif
  209.  
  210. /* These algorithms are all straight out of Knuth, vol. 2, sec. 4.3.1. */
  211.  
  212. __EXTERN long long __adddi3 __PROTO((long long u, long long v));
  213. __EXTERN long long __anddi3 __PROTO((long long u, long long v));
  214. __EXTERN long long __iordi3 __PROTO((long long u, long long v));
  215. __EXTERN long long __xordi3 __PROTO((long long u, long long v));
  216. __EXTERN long long __one_cmpldi2 __PROTO((long long u));
  217. __EXTERN long long __lshldi3 __PROTO((long long u, long int b1));
  218. __EXTERN long long __lshrdi3 __PROTO((long long u, long int b1));
  219. __EXTERN long long __ashldi3 __PROTO((long long u, long int b1));
  220. __EXTERN long long __ashrdi3 __PROTO((long long u, long int b1));
  221. __EXTERN long long __subdi3 __PROTO((long long u, long long v));
  222. __EXTERN long long __muldi3 __PROTO((long long u, long long v));
  223. __EXTERN long long __divdi3 __PROTO((long long u, long long v));
  224. __EXTERN long long __moddi3 __PROTO((long long u, long long v));
  225. __EXTERN long long __udivdi3 __PROTO((long long u, long long v));
  226. __EXTERN long long __umoddi3 __PROTO((long long u, long long v));
  227. __EXTERN long long __negdi2 __PROTO((long long u));
  228. __EXTERN void __bdiv __PROTO((unsigned short *a, unsigned short *b, unsigned short *q, unsigned short *r, size_t m, size_t n));
  229. __EXTERN SItype __cmpdi2 __PROTO((long long a, long long b));
  230. __EXTERN SItype __ucmpdi2 __PROTO((long long a, long long b));
  231. __EXTERN long long __fixunsdfdi __PROTO((double a));
  232. __EXTERN long long __fixdfdi __PROTO((double a));
  233. __EXTERN double __floatdidf __PROTO((long long u));
  234. __EXTERN int __builtin_saveregs __PROTO((void));
  235. __EXTERN unsigned SItype __fixunssfsi __PROTO((float a));
  236.  
  237. #ifdef L_adddi3
  238. static int badd __PROTO((unsigned short *a, unsigned short *b, unsigned short *c, size_t n));
  239.  
  240. long long 
  241. __adddi3 (u, v)
  242.      long long u, v;
  243. {
  244.   long a[2], b[2], c[2];
  245.   long_long w;
  246.   long_long uu, vv;
  247.  
  248.   uu.ll = u;
  249.   vv.ll = v;
  250.  
  251.   a[HIGH] = uu.s.high;
  252.   a[LOW] = uu.s.low;
  253.   b[HIGH] = vv.s.high;
  254.   b[LOW] = vv.s.low;
  255.  
  256.   badd ((unsigned short *)a, (unsigned short *)b, (unsigned short *)c, sizeof c);
  257.  
  258.   w.s.high = c[HIGH];
  259.   w.s.low = c[LOW];
  260.   return w.ll;
  261. }
  262.  
  263. static int 
  264. badd (a, b, c, n)
  265.      unsigned short *a, *b, *c;
  266.      size_t n;
  267. {
  268.   unsigned long acc;
  269.   int i;
  270.  
  271.   n /= sizeof *c;
  272.  
  273.   acc = 0;
  274.   for (i = little_end (n); is_not_msd (i, n); i = next_msd (i))
  275.     {
  276.       /* Widen before adding to avoid loss of high bits.  */
  277.       acc += (unsigned long) a[i] + b[i];
  278.       c[i] = acc & low16;
  279.       acc = acc >> 16;
  280.     }
  281.   return acc;
  282. }
  283. #endif
  284.  
  285. #ifdef L_anddi3
  286. long long 
  287. __anddi3 (u, v)
  288.      long long u, v;
  289. {
  290.   long_long w;
  291.   long_long uu, vv;
  292.  
  293.   uu.ll = u;
  294.   vv.ll = v;
  295.  
  296.   w.s.high = uu.s.high & vv.s.high;
  297.   w.s.low = uu.s.low & vv.s.low;
  298.  
  299.   return w.ll;
  300. }
  301. #endif
  302.  
  303. #ifdef L_iordi3
  304. long long 
  305. __iordi3 (u, v)
  306.      long long u, v;
  307. {
  308.   long_long w;
  309.   long_long uu, vv;
  310.  
  311.   uu.ll = u;
  312.   vv.ll = v;
  313.  
  314.   w.s.high = uu.s.high | vv.s.high;
  315.   w.s.low = uu.s.low | vv.s.low;
  316.  
  317.   return w.ll;
  318. }
  319. #endif
  320.  
  321. #ifdef L_xordi3
  322. long long 
  323. __xordi3 (u, v)
  324.      long long u, v;
  325. {
  326.   long_long w;
  327.